﻿using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;

namespace PineLake.Drmwe.Core.JWT
{
    /// <summary>
    /// JWT授权 注入服务
    /// </summary>
    public static class JwtAuthorizationStartup
    {
        /// <summary>
        /// Jwt授权注入服务(GRPC项目没有带有授权方法 Web.API 项目不需要)
        /// </summary>
        /// <param name="services"></param>
        /// <returns></returns>
        public static IServiceCollection AddJwtAuthorizationStartup(this IServiceCollection services)
        {
            services.AddAuthorization(options =>
            {
                options.AddPolicy(JwtBearerDefaults.AuthenticationScheme, policy =>
                {
                    policy.AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme);
                    policy.RequireClaim(ClaimTypes.Name);
                });
            });
            return services;
        }
    }
}
